#include <stdio.h>

struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};

ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
    if(pListHead == NULL) return NULL;
    if(k <= 0) return NULL;
    
    ListNode* fast = pListHead;
    ListNode* slow = pListHead;
    while(k-- > 0 && fast)
    {
        fast = fast->next;
    }
    if(k) return NULL; // k大于链表长度
    while(fast != NULL)
    {
        fast = fast->next;
        slow = slow->next;
    }
    return slow;
}

void Print(ListNode* head)
{
    while(head)
    {
        printf("%d\t", head->val);
        head = head->next;
    }
    printf("\n");
}
int main()
{
    ListNode head(1);
    ListNode* result = FindKthToTail(&head, 1);
    Print(result);
    return 0;
}